//
//  ShowSearchViewController.m
//  SouthChina
//
//  Created by kc on 15/7/20.
//  Copyright (c) 2015年 科创. All rights reserved.
//

#import "ShowSearchViewController.h"
#import "PersonalCenterTableViewCell.h"
#import "ShowStudentViewController.h"

@interface ShowSearchViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
{ }

@property (strong, nonatomic) IBOutlet UITableView *tableview;
@end

@implementation ShowSearchViewController
@synthesize curIndex,searchkey,arrsearchlist;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSString *sTitle;
    if ([searchkey isEqualToString:@"NJ"]) {
        sTitle = @"年级";
    }
    else if([searchkey isEqualToString:@"PROF_NAME"])
    {
        sTitle = @"专业";
    }
    else if([searchkey isEqualToString:@"CLASS_NAME"])
    {
        sTitle = @"班级";
    }
    [self addTitleBarWithBackBtn:sTitle needReturn:TRUE];
    
    UIView * viewBody = [[[NSBundle mainBundle] loadNibNamed:@"ShowSearchViewBody" owner:self options:nil] objectAtIndex:0];
    
    viewBody.frame = (CGRect){0, TITLE_BAR_HEGIHT+YNEW,SCREEN_WIDTH, SCREEN_HEIGHT-TITLE_BAR_HEGIHT-YNEW};
    [self.view addSubview:viewBody];
    
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.bounces=NO;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//列表组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
//指定标题的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrsearchlist.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"PersonalCenterTableViewCell";
    PersonalCenterTableViewCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];
    }
    cell.titleLabel.text = [arrsearchlist objectAtIndex:indexPath.row] ;
    cell.labelconstraint.constant= 30;
    cell.titleLabel.font = [UIFont boldSystemFontOfSize:13];
    //选中后显示选中图像
    if(curIndex == indexPath.row )
    {
        UIImageView * selectedImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, 22, 15, 12)];
        selectedImage.image = [UIImage imageNamed:@"单选选中.png"];
        [cell addSubview:selectedImage];
    }
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //选中某行(回传参数)
    curIndex = indexPath.row;
    //刷新列表
    [_tableview reloadData];
    //返回到上一级页面
   [self.navigationController popViewControllerAnimated:YES];
    //得到最上面那个viewcontroller
    ShowStudentViewController *viewC = [self.navigationController.viewControllers objectAtIndex:(self.navigationController.viewControllers.count-1)];
    if ([searchkey isEqualToString:@"NJ"]) {
        viewC.curIndexnj = curIndex;
        viewC.returntype = 1;
    }
    else if([searchkey isEqualToString:@"PROF_NAME"])
    {
        viewC.curIndexprof = curIndex;
        viewC.returntype = 2;
    }
    else if([searchkey isEqualToString:@"CLASS_NAME"])
    {
        viewC.curIndexclass = curIndex;
        viewC.returntype = 3;
    }
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
